//package com.ruoyi.system.controller;
//
//
//import com.ruoyi.common.utils.uuid.IdUtils;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.multipart.MultipartFile;
//import oshi.util.FileUtil;
//
//import java.io.File;
//import java.io.IOException;
//import java.nio.file.Files;
//
//@RestController
//@RequestMapping("/file")
//public class FileUploadController {
//    @Value("${files.upload.path}")
//    private String fileUploadPath;
//
//    @PostMapping("/upload")
//    public String upload(@RequestParam MultipartFile file) throws IOException {
//         String originalFilename = file.getOriginalFilename();
//         String type = FileUtil.readPropertiesFromFilename(originalFilename);
//         Long size = file.getSize();
//         //先存储到磁盘
//        File uploadParentFile = new File(fileUploadPath);
//        if(!uploadParentFile.exists()){
//            uploadParentFile.mkdirs();
//        }
//        //定义一个唯一标识码
//        String uuid = IdUtils.fastSimpleUUID();
//        File uploadFile = new File(fileUploadPath + uuid + StrUtil.DOT +type);
//        //获取文件到指定文件目录
//        file.transferTo(uploadFile);
//
//        String url="http://localhost:8080/" + uuid;
//        //存储数据库
//        Files saveFile = new Files();
//        saveFile.setName(originalFilename);
//        saveFile.setType(type);
//        saveFile.setSize(size);
//        fileMapper.insert(saveFile);
//        return url;
//    }
//}
